<?php
/**
 * Copyright (c) 2006-2007, Julien PORTALIER
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright    Copyright (c) 2006-2007, Julien PORTALIER
 * @link         http://featherphp.googlecode.com/
 * @license      http://www.opensource.org/licenses/mit-license.php The MIT License
 */

/**
 * Easy logging system.
 */
class Log
{
	private static $instance;
	protected $logs = array();
	
	private function __construct() {}
	
	function __destruct()
	{
		if (!empty($this->logs))
		{
			foreach($this->logs as $fd)
				fclose($fd);
		}
	}
	
	function instance()
	{
		if (!self::$instance)
			self::$instance = new self;
		return self::$instance;
	}
	
	function write($text, $log="default")
	{
		if (!isset($this->logs[$log]))
			$this->logs[$log] = fopen(APP.'tmp'.DS.'logs'.DS."$log.log", 'a');
		fwrite($this->logs[$log], date('Y-m-d H:i:s', time()).' '.env('REQUEST_URI')." $text\n");
	}
}

?>